package part4createthread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @description: 总结线程的创建
 * @date: 2022/10/11 20:36.
 * @version: 1.0
 */
public class CreateThreadSummary {

    public static void main(String[] args) {
        // Thread方式创建线程
        new MyThread1().start();

        // Runnable方式创建线程
        new Thread(new MyThread2(), "runnable方式").start();

        // Callable方式创建线程
        FutureTask<Integer> futureTask = new FutureTask<Integer>(new MyThread3());
        new Thread(futureTask, "callable方式创建").start();
        try {
            Integer integer = futureTask.get();
            System.out.println("MyThread3-->" + integer);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }

}

/**
 * description: 集成Thread类
 **/
class MyThread1 extends Thread {
    @Override
    public void run() {
        System.out.println("MyThread1");
    }
}

/**
 * description: 实现Runnable接口
 **/
class MyThread2 implements Runnable {
    @Override
    public void run() {
        System.out.println("MyThread2");
    }
}

/**
 * description: 实现Callable接口
 **/
class MyThread3 implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println("MyThread3");
        return 100;
    }
}